from flask import Blueprint
# 创建蓝图
from flask import redirect
from flask import render_template
from flask import request
from flask import session
from flask import url_for

admin_blu = Blueprint('admin', __name__, url_prefix='/admin')

# 与视图函数产生关联
from .views import index

@admin_blu.before_request  # 可以对蓝图设置请求钩子, 只会监听该蓝图注册的路由
def check_superuser():
    is_admin = session.get("is_admin")
    # 如果未登录管理员 且 不是访问后台登录路由
    if not is_admin and not request.url.endswith("admin/login"):
        return redirect(url_for("home.index"))
    # if not is_admin:
    #     return render_template('admin/login.html')